package com.zsrt.server;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	
	
	public static void main(String[] args) throws Exception {
		
		@SuppressWarnings("resource")
		ServerSocket ss = new ServerSocket(8888);
		
		
		while(true){
			//设计死循环可以无限处理客户端的请求
			System.out.println("等待客户端请求...");
			
			Socket socket= ss.accept();
			System.out.println("握手成功...");
			
			//通过输入流获取客户端的数据
			InputStream is = socket.getInputStream();
			
			byte[] b = new byte[1024];
			
			int len = is.read(b);
			
			String data = new String(b,0,len);
			System.out.println("接受到的客户端的数据为:"+data);
			
			//把data转化为大写
			String dataUpper = data.toUpperCase();
			
			//把大写的data写回客户端
			OutputStream os = socket.getOutputStream();
			os.write(dataUpper.getBytes());
			
			os.close();
			is.close();
			socket.close();
		}
	}

}
